/**
 * @author dxp
 * 工具类
 */
// 大写字符串首字母
function upperHead(str) {
    var head = str.charAt(0).toUpperCase();
    return head + str.substr(1);
}

//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外
function banBackSpace(e) {
    /*var ev = e || window.event;// 获取event对象
    var obj = ev.target || ev.srcElement;// 获取事件源
    var t = obj.type || obj.getAttribute('type');// 获取事件源类型
    // 获取作为判断条件的事件类型
    var vReadOnly = obj.getAttribute('readonly');
    var vEnabled = obj.getAttribute('enabled');
    // 处理null值情况
    vReadOnly = (vReadOnly == null) ? false : vReadOnly;
    vEnabled = (vEnabled == null) ? true : vEnabled;
    // 当敲Backspace键时，事件源类型为密码或单行、多行文本的，
    // 并且readonly属性为true或enabled属性为false的，则退格键失效
    var flag1=(ev.keyCode == 8 && (t=="password" || t=="text" || t=="textarea") && (vReadOnly || vEnabled!=true))?true:false;
    // 当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效
    var flag2=(ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea")?true:false;
    // 如果是F5事件
    if (ev.type == "keydown" && ev.keyCode == 116){
        if(location.pathname.indexOf("/frm/main")=="-1"){
            location.reload();
        }
        return false;
    }
    // 判断
    if(flag2){
        return false;
    }
    if(flag1){
        return false;
    }*/
    return true;
}

// 禁止后退键 作用于Firefox、Opera
document.onkeypress = banBackSpace;
// 禁止后退键 作用于IE、Chrome
document.onkeydown = banBackSpace;

/**
 * 时间对象的格式化;
 */
Date.prototype.format = function (format) {
    /*
     * eg:format="yyyy-MM-dd hh:mm:ss";
     */
    var o = {
        "M+": this.getMonth() + 1, // month
        "d+": this.getDate(), // day
        "h+": this.getHours(), // hour
        "m+": this.getMinutes(), // minute
        "s+": this.getSeconds(), // second
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
        "S": this.getMilliseconds()
    };
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
            - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
};

/**
 * 时间字符串转时间
 */
function yMdhfm2msec(yMdhfm) {
    if (yMdhfm) {
        return new Date(yMdhfm.replace(/-/g, "/")).getTime();
    }
    return -1;
}

function ajaxErrorDeal(request, textStatus, errorThrown) {
    // "timeout", "error", "notmodified" 和 "parsererror"
    // 通常 textStatus 和 errorThrown 之中 只有一个会包含信息
    // 调用本次AJAX请求时传递的options参数
    if ('timeout' == textStatus) {
        alertModel('访问超时');
    } else if ('error' == textStatus) {
        switch (request.status) {
            case 0:
                return;
            case 401:
                return;
            case 403:
                return;
            case 410:
                return;
            case 404:
                return;
            case 500:
                alertModel("服务器端出现异常，请联系管理员");
                return;
        }
        alertModel('错误代码：' + request.status + "\n" + textStatus + "\n" + errorThrown);
    } else if ('parsererror' == textStatus) {
        alertModel('解析异常');
    }
}

var alertModelCloseTime = 0;

/**
 * 提示框
 * @param warnInfo 信息
 * @param funName 回调函数，非字符串，不能有括号！
 * @param args 回调函数的参数
 */
function alertModel(warnInfo, funName, args) {
    if ($('#_frm_warn_modal').length > 0) {
        $('#_frm_warn_modal').remove();
    }
    var content = '\
    <div class="modal fade" style="z-index:2000;" id="_frm_warn_modal" tabindex="-1" role="dialog" aria-labelledby="_frm_warn_modal_label">\
      <div class="modal-dialog" role="document">                                                    \
        <div class="modal-content" style="max-width:800px;">                                                                 \
          <div class="modal-header">                                                                \
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">            \
              <span aria-hidden="true">&times;</span>                                               \
            </button>                                                                               \
            <h4 class="modal-title" id="_frm_warn_modal_label">提示</h4>                             \
          </div>                                                                                    \
          <div class="modal-body" id="_frm_warn_modal_body">                                        \
          </div>                                                                                    \
          <div class="modal-footer">                                                                \
    	    <font><a id="_frm_warn_modal_close"></a>秒后自动关闭</font>                                 \
            <button type="button" class="btn btn-close" data-dismiss="modal">关闭</button>           \
          </div>                                                                                    \
        </div>                                                                                      \
      </div>                                                                                        \
    </div>';
    $('body').append(content);
    //增加关闭监听事件
    $('#_frm_warn_modal').off().on('hidden.bs.modal', function (e) {
        $('#_frm_warn_modal').remove();
        alertModelCloseTime = 0;//0表示已经关闭
        if (funName)
            funName(args);
    });
    $('#_frm_warn_modal_body').html(warnInfo);
    $('#_frm_warn_modal').modal('show');
    alertModelCloseTime = 10;//10秒后关闭
    //定时关闭功能
    alertModelSetTimeout();
}

//定时关闭
function alertModelSetTimeout() {
    alertModelCloseTime--;//倒计时减1
    if (alertModelCloseTime <= 0) {
        console.log("关闭" + alertModelCloseTime);
        $('#_frm_warn_modal_close').html('');
        $('#_frm_warn_modal').modal('hide');
    } else {
        console.log("倒计时" + alertModelCloseTime);
        $('#_frm_warn_modal_close').html(alertModelCloseTime);
        setTimeout("alertModelSetTimeout()", 1000);
    }
}

/**
 * 确认框，
 * @param confirmInfo 信息
 * @param funName 回调函数，非字符串，不能有括号！
 * @param args 回调函数的参数
 */
function confirmModel(confirmInfo, funName, args) {
    var content = '\
    <div class="modal fade" style="z-index:2000;" id="_frm_confirm_modal" tabindex="-1" role="dialog" aria-labelledby="_frm_confirm_modal_label">\
      <div class="modal-dialog" role="document">                                                    \
        <div class="modal-content" style="max-width:800px;">                                                                 \
          <div class="modal-header">                                                                \
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">            \
                <span aria-hidden="true">&times;</span>                                             \
            </button>                                                                               \
            <h4 class="modal-title" id="_frm_confirm_modal_label">提示</h4>                          \
          </div>                                                                                    \
          <div class="modal-body" id="_frm_confirm_modal_body">                                     \
          </div>                                                                                    \
          <div class="modal-footer">                                                                \
    		<button type="button" class="btn btn-info"  id="_frm_confirm_modal_yes" >确定</button>   \
            <button type="button" class="btn btn-close" data-dismiss="modal">关闭</button>           \
          </div>                                                                                    \
        </div>                                                                                      \
      </div>                                                                                        \
    </div>';
    if ($('#_frm_confirm_modal').size() == 0) {
        $('body').append(content);
    }
    $('#_frm_confirm_modal').off().on('hidden.bs.modal', function (e) {
        $('#_frm_confirm_modal').remove();
    });
    $('#_frm_confirm_modal_yes').off().on("click", function () {
        $('#_frm_confirm_modal').modal('hide');
        funName(args);
    });

    $('#_frm_confirm_modal_body').html(confirmInfo);
    $('#_frm_confirm_modal').modal('show');
}

function confirmModelStatus(confirmInfo, funName, args) {
    var content = '\
    <div class="modal fade" style="z-index:2000" id="_frm_confirm_modal_status" tabindex="-1" role="dialog" aria-labelledby="_frm_confirm_modal_status_label">\
      <div class="modal-dialog" role="document">                                                    \
        <div class="modal-content">                                                                 \
          <div class="modal-header">                                                                \
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">            \
                <span aria-hidden="true">&times;</span>                                             \
            </button>                                                                               \
            <h4 class="modal-title" id="_frm_confirm_modal_status_label">提示</h4>                            \
          </div>                                                                                    \
          <div class="modal-body" id="_frm_confirm_modal_status_body">                                        \
          </div>                                                                                    \
          <div class="modal-footer">                                                                \
    		<button type="button" class="btn btn-info"  id="_frm_confirm_modal_status_yes" >确定</button>        \
            <button type="button" class="btn btn-close" id="_frm_confirm_modal_status_no">关闭</button>        \
          </div>                                                                                    \
        </div>                                                                                      \
      </div>                                                                                        \
    </div>';
    if ($('#_frm_confirm_modal_status').size() == 0) {
        $('body').append(content);
    }
    $('#_frm_confirm_modal_status').off().on('hidden.bs.modal', function (e) {
        funName(null, args);
        $('#_frm_confirm_modal_status').remove();
    });
    $('#_frm_confirm_modal_status_yes').off().on("click", function () {
        $('#_frm_confirm_modal_status').modal('hide');
        funName(true, args);
    });
    $('#_frm_confirm_modal_status_no').off().on("click", function () {
        $('#_frm_confirm_modal_status').modal('hide');
        funName(false, args);
    });

    $('#_frm_confirm_modal_status_body').html(confirmInfo);
    $('#_frm_confirm_modal_status').modal('show');
}

function alertBlock(warnInfo) {
    var content = '\
		<div id="_frm_confirm_block_alert" style=" cursor: default;z-index:2000;"> \
			<div>提示</div>\
	        <div id="_frm_confirm_block_alert_info"></div>\
	        <div><a class="btn btn-close" onclick="$.unblockUI();">关闭</a></div>\
	    </div>';
    $.blockUI({onOverlayClick: $.unblockUI, message: content});
    $('#_frm_confirm_block_alert_info').html(warnInfo);
}

function confirmBlock(confirmInfo, funName, args) {
    var content = '\
		<div id="_frm_confirm_block" class="modal_alert" style=" cursor: default;z-index:2000;"> \
			<div>提示</div>\
	        <div id="_frm_confirm_block_info"></div>\
	        <div><a class="btn btn-info" id="_frm_block_confirm_yes">确定</a>\
		<a class="btn btn-close" id="_frm_block_confirm_no">关闭</a></div>\
	    </div>';
    $.blockUI({
        onOverlayClick: function () {
            $.unblockUI
        }, message: content
    });
    $('#_frm_confirm_block_info').html(confirmInfo);
    $('#_frm_block_confirm_yes').off().on("click", function () {
        $.unblockUI();
        funName(args);
    });
    $('#_frm_block_confirm_no').off().on("click", function () {
        $.unblockUI();
    });
}

function confirmBlockStatus(confirmInfo, funName, args) {
    var content = '\
		<div id="_frm_confirm_status_block" class="modal_alert" style=" cursor: default;z-index:2000;"> \
			<div>提示</div>\
	        <div id="_frm_confirm_status_block_info"></div>\
	        <div><a class="btn btn-info" id="_frm_confirm_status_block_yes">确定</a>\
		<a class="btn btn-close" id="_frm_confirm_status_block_no">关闭</a></div>\
	    </div>';
    $.blockUI({onOverlayClick: $.unblockUI, message: content});
    $('#_frm_confirm_status_block_info').html(confirmInfo);
    $('#_frm_confirm_status_block_yes').off().on("click", function () {
        $.unblockUI();
        funName(true, args);
    });
    $('#_frm_confirm_status_block_no').off().on("click", function () {
        $.unblockUI();
        funName(false, args);
    });

}

function confirmModel1(confirmInfo, funName, args, args1) {
    var content = '\
    <div class="modal fade" style="z-index:2000" id="_frm_confirm_modal" tabindex="-1" role="dialog" aria-labelledby="_frm_confirm_modal_label">\
      <div class="modal-dialog" role="document">                                                    \
        <div class="modal-content">                                                                 \
          <div class="modal-header">                                                                \
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">            \
                <span aria-hidden="true">&times;</span>                                             \
            </button>                                                                               \
            <h4 class="modal-title" id="_frm_confirm_modal_label">提示</h4>                            \
          </div>                                                                                    \
          <div class="modal-body" id="_frm_confirm_modal_body">                                        \
          </div>                                                                                    \
          <div class="modal-footer">                                                                \
    		<button type="button" class="btn btn-info"  id="_frm_confirm_modal_yes" >确定</button>        \
            <button type="button" class="btn btn-close" data-dismiss="modal">关闭</button>        \
          </div>                                                                                    \
        </div>                                                                                      \
      </div>                                                                                        \
    </div>';
    if ($('#_frm_confirm_modal').size() == 0) {
        $('body').append(content);
    }
    $('#_frm_confirm_modal').off().on('hidden.bs.modal', function (e) {
        $('#_frm_confirm_modal').remove();
    });
    $('#_frm_confirm_modal_yes').off().on("click", function () {
        $('#_frm_confirm_modal').modal('hide');
        funName(args, args1);
    });

    $('#_frm_confirm_modal_body').html(confirmInfo);
    $('#_frm_confirm_modal').modal('show');
}

function confirmModel2(confirmInfo, funName, args, args1, args2) {
    var content = '\
    <div class="modal fade" style="z-index:2000" id="_frm_confirm_modal" tabindex="-1" role="dialog" aria-labelledby="_frm_confirm_modal_label">\
      <div class="modal-dialog" role="document">                                                    \
        <div class="modal-content">                                                                 \
          <div class="modal-header">                                                                \
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">            \
                <span aria-hidden="true">&times;</span>                                             \
            </button>                                                                               \
            <h4 class="modal-title" id="_frm_confirm_modal_label">提示</h4>                            \
          </div>                                                                                    \
          <div class="modal-body" id="_frm_confirm_modal_body">                                        \
          </div>                                                                                    \
          <div class="modal-footer">                                                                \
    		<button type="button" class="btn btn-info"  id="_frm_confirm_modal_yes" >确定</button>        \
            <button type="button" class="btn btn-close" data-dismiss="modal">关闭</button>        \
          </div>                                                                                    \
        </div>                                                                                      \
      </div>                                                                                        \
    </div>';
    if ($('#_frm_confirm_modal').size() == 0) {
        $('body').append(content);
    }
    $('#_frm_confirm_modal').off().on('hidden.bs.modal', function (e) {
        $('#_frm_confirm_modal').remove();
    });
    $('#_frm_confirm_modal_yes').off().on("click", function () {
        $('#_frm_confirm_modal').modal('hide');
        funName(args, args1, args2);
    });

    $('#_frm_confirm_modal_body').html(confirmInfo);
    $('#_frm_confirm_modal').modal('show');
}

function confirmModel2(confirmInfo, funName, args, args1, args2, args3) {
    var content = '\
    <div class="modal fade" style="z-index:2000" id="_frm_confirm_modal" tabindex="-1" role="dialog" aria-labelledby="_frm_confirm_modal_label">\
      <div class="modal-dialog" role="document">                                                    \
        <div class="modal-content">                                                                 \
          <div class="modal-header">                                                                \
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">            \
                <span aria-hidden="true">&times;</span>                                             \
            </button>                                                                               \
            <h4 class="modal-title" id="_frm_confirm_modal_label">提示</h4>                            \
          </div>                                                                                    \
          <div class="modal-body" id="_frm_confirm_modal_body">                                        \
          </div>                                                                                    \
          <div class="modal-footer">                                                                \
    		<button type="button" class="btn btn-info"  id="_frm_confirm_modal_yes" >确定</button>        \
            <button type="button" class="btn btn-close" data-dismiss="modal">关闭</button>        \
          </div>                                                                                    \
        </div>                                                                                      \
      </div>                                                                                        \
    </div>';
    if ($('#_frm_confirm_modal').size() == 0) {
        $('body').append(content);
    }
    $('#_frm_confirm_modal').off().on('hidden.bs.modal', function (e) {
        $('#_frm_confirm_modal').remove();
    });
    $('#_frm_confirm_modal_yes').off().on("click", function () {
        $('#_frm_confirm_modal').modal('hide');
        funName(args, args1, args2, args3);
    });

    $('#_frm_confirm_modal_body').html(confirmInfo);
    $('#_frm_confirm_modal').modal('show');
}

//切换tab，iframe滚动条不显示问题解决方案：重置页面高度，重绘滚动条
function fixSize(iframeId) {
    try {
        // 设置内部页面body高度，-1再+1用于处理google浏览器切换tab不显示滚动条的问题
        var x = document.getElementById(iframeId);
        var childFrame = (x.contentWindow || x.contentDocument);
        childFrame.document.body.style.overflow = "hidden";
        childFrame.document.body.scrollWidth;
        childFrame.document.body.style.overflow = "auto";
    } catch (e) {
    }
}

/**
 * 表单赋值方法
 */
$.fn.setForm = function (jsonValue) {
    var obj = this;
    $.each(jsonValue, function (name, ival) {
        var $oinput = obj.find("[name='" + name + "']");
        if ($oinput.attr("type") === "checkbox") {
            if (ival !== null) {
                var checkArray = ival.split(",");
                for (var j = 0; j < checkArray.length; j++) {
                    $("input[name='" + name + "'][value='" + checkArray[j] + "']").prop("checked");
                }
            }
        } else if ($oinput.attr("type") === "radio") {
            $("input[name='" + name + "'][value='" + ival + "']").prop("checked", true);
        } else if ($oinput.attr("nodeName") === "textarea") {
            obj.find("[name='" + name + "']").html(ival);
        } else if ($oinput.attr("tagName") === "select") {
            $("select[name='" + name + "'] option[value='" + ival + "']").prop("selected", "selected");
        } else {
            obj.find("[name='" + name + "']").val(ival);
        }
    })
};
var global_getconfigval;

//获取系统配置值
function getConfigVal(code) {
    var result = {};
    if (!global_getconfigval) {
        $.ajax({
            type: "post",
            url: prc + "/sysConfigController/getVal",
            "contentType": 'application/x-www-form-urlencoded; charset=UTF-8',
            data: {
                code: code
            },
            async: false,
            dataType: "json",
            success: function (data) {
                result = data.result;
                global_getconfigval = data.result;
            }
        });
    } else {
        result = global_getconfigval;
        //console.log("返回全局变量的翻页参数，省去调用翻页数据的时间")
    }
    return result;
}

//获取系统配置值,分隔符处理后的数组
function getLength(code) {
    try {
        if (parent.menuLength) {
            //console.log("返回父页面的翻页参数，省去调用翻页数据的时间")
            return parent.menuLength;
        }
    } catch (e) {
    }
    var result = getConfigVal(code);
    if (null != result) {
        var menuLength = result.split(",");
        for (i = 0; i < menuLength.length; i++) {
            var aa = parseInt(menuLength[i]);
            menuLength[i] = aa;
        }
        return menuLength;
    }
    return "";
}

/**
 * 字典下拉框封装方法[控制登录用户权限]
 * （不负责清空，不负责添加请选择，
 * 如有需要自行清空$("#"+eId).empty();
 * 如有需要自行添加$("#"+eId).append("<option value=''>---请选择---</option>");）
 * @param eId 下拉框元素id
 * @param dictType 字典类型
 * @param setValue 加载完毕后设置值（可为null）
 * @returns
 */
function makeSelectForDictType(eId, dictType, setValue) {
    $.ajax({
        url: prc + "/sysDict/getDictList",
        data: {type: dictType},
        dataType: "JSON",
        type: "post",
        success: function (data) {
            var html = "";
            $.each(data, function (index, item) {
                html += "<option value=\"" + item.dictValue + "\">" + item.dictLabel + "</option>";
            });
            $("#" + eId).append(html);
            if (setValue) {
                $("#" + eId).val(setValue);
            }
        }
    });
}

/**
 * 字典级联-子项-下拉框封装方法[控制登录用户权限]
 * （不负责清空，不负责添加请选择，
 * 如有需要自行清空$("#"+eId).empty();
 * 如有需要自行添加$("#"+eId).append("<option value=''>---请选择---</option>");）
 * @param eId 下拉框元素id
 * @param dictType 字典类型
 * @param dictValue 父级字典值
 * @param setValue 加载完毕后设置值（可为null）
 */
function makeSelectForDictLink(eId, dictType, dictValue, setValue) {
    $.ajax({
        url: prc + "/sysDict/getDictListByLink",
        data: {type: dictType, value: dictValue},
        dataType: "JSON",
        type: "post",
        success: function (data) {
            var html = "";
            $.each(data, function (index, item) {
                html += "<option value=\"" + item.dictValue + "\">" + item.dictLabel + "</option>";
            });
            $("#" + eId).append(html);
            if (setValue) {
                $("#" + eId).val(setValue);
            }
        }
    });
}

//列表格式化金额
function table_format_money(value, row, index) {
    return common_format_money(value);
}

//格式化金额
function common_format_money(val) {
    if ('undefined' == typeof (val) || '' == val || val.length <= 0) {
        return "0.00";
    }
    try {
        val = parseFloat(val).toFixed(2);
        var m = val.toString().split('.');
        return (m[0] || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + "." + m[1];
    } catch (e) {
        return "0.00";
    }
}

/**
 *列表格式化金额(5位) 用于表格
 */
function table_format_money_fixed5(value, row, index) {
    return common_format_money_fixed5(value);
}

/**
 *列表格式化金额(5位)
 */
function common_format_money_fixed5(val) {
    if ('undefined' == typeof (val) || '' == val || val.length <= 0) {
        return "0.00000";
    }
    try {
        val = parseFloat(val).toFixed(5);
        var m = val.toString().split('.');
        return (m[0] || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + "." + m[1];
    } catch (e) {
        return "0.00000";
    }
}

/*===================================================计算公共函数 开始==============================================================================*/

//乘
function floatMul(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try {
        m += s1.split(".")[1].length
    } catch (e) {
    }
    try {
        m += s2.split(".")[1].length
    } catch (e) {
    }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
}

//除
function floatDiv(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try {
        t1 = arg1.toString().split(".")[1].length
    } catch (e) {
    }
    try {
        t2 = arg2.toString().split(".")[1].length
    } catch (e) {
    }
    r1 = Number(arg1.toString().replace(".", ""));
    r2 = Number(arg2.toString().replace(".", ""));
    return (r1 / r2) * Math.pow(10, t2 - t1);
}

//加
function floatAdd(arg1, arg2) {
    var r1, r2, m;
    try {
        r1 = arg1.toString().split(".")[1].length
    } catch (e) {
        r1 = 0
    }
    try {
        r2 = arg2.toString().split(".")[1].length
    } catch (e) {
        r2 = 0
    }
    m = Math.pow(10, Math.max(r1, r2));
    return (arg1 * m + arg2 * m) / m;
}

//减
function floatSub(arg1, arg2) {
    var r1, r2, m, n;
    try {
        r1 = arg1.toString().split(".")[1].length
    } catch (e) {
        r1 = 0
    }
    try {
        r2 = arg2.toString().split(".")[1].length
    } catch (e) {
        r2 = 0
    }
    m = Math.pow(10, Math.max(r1, r2));
    //动态控制精度长度
    n = (r1 >= r2) ? r1 : r2;
    return ((arg1 * m - arg2 * m) / m).toFixed(n);
}

//保留两位小数
function round2(num) {
    n = Math.round(num * 100) / 100;
    return n.toFixed(2);
}

/**可编辑表格手动提交*/
function editableSubmit() {
    try {
        $(".editableform").submit();
    } catch (e) {
    }
}

String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, 'gm'), s2);
};


/**
 * String 重写toFixed方法，重新计算执行四舍五入方法
 * @d 需要四舍五入的值
 */
String.prototype.toFixed = function (d) {
    var s = this + "";
    if (!d) d = 0;
    if (s.indexOf(".") == -1) s += ".";
    s += new Array(d + 1).join("0");
    if (new RegExp("^(-|\\+)?(\\d+(\\.\\d{0," + (d + 1) + "})?)\\d*$").test(s)) {
        var s = "0" + RegExp.$2, pm = RegExp.$1, a = RegExp.$3.length, b = true;
        if (a == d + 2) {
            a = s.match(/\d/g);
            if (parseInt(a[a.length - 1]) > 4) {
                for (var i = a.length - 2; i >= 0; i--) {
                    a[i] = parseInt(a[i]) + 1;
                    if (a[i] == 10) {
                        a[i] = 0;
                        b = i != 1;
                    } else break;
                }
            }
            s = a.join("").replace(new RegExp("(\\d+)(\\d{" + d + "})\\d$"), "$1.$2");

        }
        if (b) s = s.substr(1);
        return (pm + s).replace(/\.$/, "");
    }
    return this + "";

};
/**
 * 数值 重写toFixed方法，重新计算执行四舍五入方法
 * @d 需要四舍五入的值
 */
Number.prototype.toFixed = function (d) {
    var s = this + "";
    if (!d) d = 0;
    if (s.indexOf(".") == -1) s += ".";
    s += new Array(d + 1).join("0");
    if (new RegExp("^(-|\\+)?(\\d+(\\.\\d{0," + (d + 1) + "})?)\\d*$").test(s)) {
        var s = "0" + RegExp.$2, pm = RegExp.$1, a = RegExp.$3.length, b = true;
        if (a == d + 2) {
            a = s.match(/\d/g);
            if (parseInt(a[a.length - 1]) > 4) {
                for (var i = a.length - 2; i >= 0; i--) {
                    a[i] = parseInt(a[i]) + 1;
                    if (a[i] == 10) {
                        a[i] = 0;
                        b = i != 1;
                    } else break;
                }
            }
            s = a.join("").replace(new RegExp("(\\d+)(\\d{" + d + "})\\d$"), "$1.$2");

        }
        if (b) s = s.substr(1);
        return (pm + s).replace(/\.$/, "");
    }
    return this + "";

};
/*===================================================计算公共函数 结束==============================================================================*/
